// pages/contactMode/contactMode.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
      cardaddress:'',
      cardid:'',
      cardmingcheng:'',//公司名称
      cardname:'',
      cardphone:'',
      cardresponsiblearea:'',
      cardstatus:'',
      cardvx:'',
      cardpassword:''
  },
  // 保存名片截图
  keeppicture:function(){
    // console.log('截图')
    const wxGetImageInfo = promisify(wx.getImageInfo)

    wx.GetImageInfo({
        src: '../../images/signIn/white.png'
    }).then(res => {
        const ctx = wx.createCanvasContext('shareCanvas')
        ctx.drawImage(res.path, 0, 0, 600, 900)
         // 作者名称
        ctx.setTextAlign('center')    // 文字居中
        ctx.setFillStyle('#000000')  // 文字颜色：黑色
        ctx.setFontSize(22)         // 文字字号：22px
        ctx.fillText("作者：一斤代码", 600 / 2, 500)
        
        ctx.stroke()
        ctx.draw()

    })
    const wxCanvasToTempFilePath = promisify(wx.canvasToTempFilePath)
    const wxSaveImageToPhotosAlbum = promisify(wx.saveImageToPhotosAlbum)

    wxCanvasToTempFilePath({
        canvasId: 'shareCanvas'
    }, this).then(res => {
        return wxSaveImageToPhotosAlbum({
            filePath: res.tempFilePath
        })
    }).then(res => {
        wx.showToast({
            title: '已保存到相册'
        })
    })

  },

  // 拨打电话
  phoneCall:function(){
    var that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.cardphone,
      success: function () {
        console.log("成功拨打电话")
        
        },
    })
  },
  // 复制微信
  copy:function(){
    var that = this
    wx.setClipboardData({
      data: that.data.cardphone,
      success (res) {
        wx.getClipboardData({
          success (res) {
            console.log(res.data) // data
          }
        })
      }
    })
  },
  // 复制邮箱
  copyemail:function(){
    var that = this
    wx.setClipboardData({
      data: that.data.cardpassword,
      success (res) {
        wx.getClipboardData({
          success (res) {
            console.log(res.data) // data
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('options',options)
    this.setData({
      cardaddress:options.cardaddress,
      cardid:options.cardid,
      cardmingcheng:options.cardmingcheng,
      cardname:options.cardname,
      cardphone:options.cardphone,
      cardresponsiblearea:options.cardresponsiblearea,
      cardstatus:options.cardstatus,
      cardvx:options.cardvx,
      cardpassword:options.cardPassword,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})